﻿@{
    Layout = "~/Views/Shared/_level1.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
    <link href="/SiteUI/MyBiz/Dashbord.css" rel="stylesheet" />  
}
<title>天联云-我的工作桌面</title>

<div class="col-lg-8" id="widget">
    <div class="row wgSetting">
        <div class="col-lg-2 col-lg-offset-4 dataRange onlymine" data-range="onlymine">我的工作台</div>
        <div class="col-lg-2 dataRange dept" data-range="dept">部门工作台</div>
    </div>
    <div id="hlpEmptyDashbord">
        <h5><b>请告诉我们您的主要工作内容：</b></h5>
        <br />
        <div class="row">
            <div class="col-lg-2 col-lg-offset-2 choiceRole">
                <img src="~/SiteUI/Imgs/Dashbord-buyer.png" style="height:100%" /><br />
                <h6>我是“采购员”</h6>
                <span class="cashbord_color" id="buyer">选择</span>
            </div>
            <div class="col-lg-2 col-lg-offset-1 choiceRole">
                <img src="~/SiteUI/Imgs/Dashbord-supplier.png" style="height:100%" /><br />
                <h6>我是“销售员”</h6>
                <span class="cashbord_color" id="supplier">选择</span>
            </div>
            <div class="col-lg-2 col-lg-offset-1 col-lg-m choiceRole">
                <img src="~/SiteUI/Imgs/Dashbord-consignee.png" style="height:100%" /><br />
                <h6>我是“收货人”</h6>
                <span class="cashbord_color" id="consignee">选择</span>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-10 cashbord_float">也可以选择&nbsp;:&nbsp;<a class="button btn-focus" href="/MyBiz/MyNavi?go=widget">我最关心的内容</a></div>
        </div>
    </div>
</div>
<div class="col-lg-4" id="widgetLite">
    <div class="row" id="acntInfo">
        <img />
        <div class="col-lg-12" id="userBaseInfo">
            <h4 id="ubi-name"></h4>
            <h5 id="ubi-org"></h5>
            <h6 id="ubi-position"></h6>
            <div class="row">
            </div>
        </div>
    </div>
    <div class="row" id="myTodo">
        <div class="col-lg-6" id="mtd-tab">我的待办</div>
        <div class="col-lg-12" id="lstMyTodos">
            <div class="empty"><i class="icon-kafeicoffee61"></i>暂无待办记录</div>
            <div class="loading"><i class="icon-loop"></i>正在努力加载...</div>
        </div>
    </div>
</div>

<script>
    Dashbord = {
        Todos: null,
        onUserReady: function (ev) {
            //动态加载用户启用的挂件
            $("#acntInfo img").attr("src", User.headimg);
            $("#ubi-name").vl(User.realname || User.username);

            //TODO:第一个公司节点或设置中指定的公司节点
            var c = User.Orgs.findObj("companyidstr", null);
            $("#ubi-org").vl(c == null ? "-" : c.realname);

            if (User.Positions.length > 0) {
                $("#ubi-position").vl(User.Positions[0].name);
            }

            if (User.setting && User.setting.Widgets) {
                if (User.setting.Widgets.findObj("Active", true) == null) {
                    //TODO:桌面显示‘为什么这里空空如野，引导用户去设置桌面部件’
                    $("#hlpEmptyDashbord").show();
                }

                //加载用户启用的桌面部件
                User.setting.Widgets.forEach(function (i) {
                    var wgt = $("<div class='row'>");
                    if (i.Active) {
                        if (i.Size == 'normal') {
                            wgt.appendTo("#widget");
                        }
                        else {
                            wgt.appendTo("#widgetLite");
                        }
                        wgt.load(i.Url);
                    }
                });
            }

            User.DataRange = {};
            User.DataRange.onlymine = $.Cookie("DataRange-onlymine") || false;
            if (User.DataRange.onlymine) {
                $(".wgSetting").children(".onlymine").addClass("current");
            }
            else {
                $(".wgSetting").children(".dept").addClass("current");
            }
        },
        onGetTodoEnd: function (rtn) {
            if (rtn.Data.Todos && rtn.Data.Todos.length > 0) {
                Dashbord.Todos = rtn.Data.Todos;
            }
            else {
                $("#lstMyTodos>.empty").show();
            }
        },
        setBuyer: function () {
            User.setting = quickSetting.buyer;
            $.post("/MyBiz/UpdateAcntSetting", { setting: JSON.stringify(User.setting) });
            success("成功", "设置完成", 3, function () { window.history.go(0); });
        },
        setConsignee: function () {
            User.setting = quickSetting.consignee;
            $.post("/MyBiz/UpdateAcntSetting", { setting: JSON.stringify(User.setting) });
            success("成功", "设置完成", 3, function () { window.history.go(0); });
        },
        setSupplier: function () {
            User.setting = quickSetting.supplier;
            $.post("/MyBiz/UpdateAcntSetting", { setting: JSON.stringify(User.setting) });
            success("成功", "设置完成", 3, function () { window.history.go(0); });
        },
    };
      
    $(function () {
        $("body").off("UserReady").on("UserReady", Dashbord.onUserReady);
        $(".dataRange").on("click", function (ev) {
            var dr = $(ev.currentTarget);
            if (dr.hasClass("current")) {
                return;
            }
            $(".dataRange.current").removeClass("current");
            dr.addClass("current");
            switch (dr.attr("data-range")) {
                case 'onlymine':
                    $.Cookie("DataRange-onlymine", true);
                    User.DataRange.onlymine = true;
                    break;
                case 'dept':
                    User.DataRange.onlymine = false;
                    $.Cookie("DataRange-onlymine", false);
                    break;
            }
            $("body").trigger("DataRangeChanged");
        });

        $("#lstMyTodos>.empty").hide();
        $("#lstMyTodos>.loading").hide();

        $("#buyer").on("click", Dashbord.setBuyer);
        $("#supplier").on("click", Dashbord.setSupplier);
        $("#consignee").on("click", Dashbord.setConsignee);

        $(".Searcher").prependTo("#widgetLite").fadeIn();
    })
</script>


